﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HelloMinasan.Business;
using HelloMinasan.Business.Extend;
using HelloMinasan.Domain;

namespace HelloMinasan.Web.Song.ViewModels
{
    public partial class SongViewModels
    {
        public HelloMinasan.Domain.Song Song { get; set; }

        public int SongId { get; set; }

        [Required]
        [DataType(DataType.Text)]
        [Display(Name = "Song name")]
        public string SongName { get; set; }

        public DateTime PostedDate { get; set; }

        [DataType(DataType.Text)]
        [Display(Name = "English Lyrics")]
        public List<LyricDetail> Lyrics { get; set; }

        [DataType(DataType.Text)]
        [Display(Name = "Song Image")]
        public string Images { get; set; }

        public string Owners { get; set; }

        [DataType(DataType.Text)]
        [Display(Name = "Grammar")]
        public string Grammar { get; set; }

        public bool IsLocked { get; set; }

        public int TypeSongId { get; set; }

        [Display(Name = "Song URL")]
        public string SongURL { get; set; }

        public string URL { get; set; }

        public string OrginalLyric { get; set; }

        private bool canUpdateLyric = true;
        public bool CanUpdateLyric {
            get { return canUpdateLyric; }
            set { canUpdateLyric = value; }
        }

        public HttpPostedFileBase ImageFile { get; set; }

        public HttpPostedFileBase SongFile { get; set; }

        public IEnumerable<HelloMinasan.Domain.Song> RelativeSongs
        {
            get{
                //return new SongRepository().GetRelativeSong(Song);

                ISongService songService = DependencyResolver.Current.GetService<ISongService>();
                return songService.GetRelativeSong(Song);
            }
        }

        [Required]
        [Display(Name = "Singer")]
        public string Singer { get; set; }

        [Required]
        [Display(Name = "Composer")]
        public string Composer { get; set; }

        public bool IsEmbed { get; set; }

        public List<SelectListItem> LanguageList 
        {
            get
            {
                //var languages = new SongRepository().GetLanguage(false, SongId).ToList();

                ISongService songService = DependencyResolver.Current.GetService<ISongService>();
                var languages = songService.GetLanguage(false, SongId).ToList();

                List<SelectListItem> listItem = new List<SelectListItem>();
                languages.ForEach((x) =>
                {
                    //listItem.Add(new SelectListItem() { Text = x.LanguageName, Value = x.LanguageId.ToString() });
                    listItem.Add(new SelectListItem() { Text = x.Name, Value = x.Id.ToString() });
                });
                return listItem;
            }
        }

        public string SelectedLanguage { get; set; }

        public bool IsEdit { get; set; }

        private bool canUpdateGrammar = true;
        public bool CanUpdateGrammar {
            get { return canUpdateGrammar; }
            set { canUpdateGrammar = value; }
        }

        public int SongView { get; set; }
    }


    public class SongAdminModel
    {
        public IEnumerable<HelloMinasan.Domain.Song> ListSong { get; set; }
        public int TotalSong { get; set; }
        public int TotalPageCount
        {
            get
            {
                int pageCount = TotalSong / 15;
                if (pageCount * 15 < TotalSong) pageCount++;
                return pageCount;
            }
        }
        public PagingHelper PagingControl { get; set; }
    }
}